﻿using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace HML.Design
{
    /// <summary>
    /// PersonPicture控件设计模式行为
    /// </summary>
    public class PersonPictureDesigner : ControlDesigner
    {
        public override SelectionRules SelectionRules
        {
            get
            {
                return base.SelectionRules & ~(SelectionRules.TopSizeable | SelectionRules.LeftSizeable);
            }
        }

        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            this.DrawTipText(pe.Graphics);
        }

        /// <summary>
        /// 绘制提示文本
        /// </summary>
        /// <param name="graphics"></param>
        private void DrawTipText(Graphics graphics)
        {
            PersonPicture control = (PersonPicture)this.Control;
            if (control.Image == null)
            {
                string text = "头像";
                SizeF text_size = graphics.MeasureString(text, control.Font);
                SolidBrush text_sb = new SolidBrush((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.StyleAppearance.BackColor));
                graphics.DrawString(text, control.Font, text_sb, new RectangleF(control.ClientRectangle.X + (control.ClientRectangle.Width - text_size.Width) / 2f, control.ClientRectangle.Y + (control.ClientRectangle.Height - text_size.Height) / 2f, text_size.Width, text_size.Height));
                text_sb.Dispose();
            }
        }

    }
}
